package com.example.wineknower.activity;

import android.Manifest;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import androidx.annotation.NonNull;


import com.example.wineknower.fragment.ShujuFragment;
import com.example.wineknower.utils.OkHttpUtil;
import com.example.wineknower.utils.UserUtil;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.AppCompatActivity;

import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;

import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;


import com.example.wineknower.R;
import com.example.wineknower.adapter.ViewPagerAdapter;
import com.example.wineknower.fragment.TouTiaoFragment;
import com.example.wineknower.fragment.HomeFragment;
import com.example.wineknower.fragment.ZixunFragment;
import com.example.wineknower.fragment.JingyingFragment;
import com.example.wineknower.utils.ActivityUtils;

import com.google.android.material.navigation.NavigationView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.tencent.connect.UserInfo;
import com.tencent.connect.auth.QQToken;
import com.tencent.connect.common.Constants;
import com.tencent.connect.share.QQShare;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {


//    @BindView(R.id.navigation)
//    BottomNavigationView navigation;
    @BindView(R.id.foot_nav_view)
    BottomNavigationView navigation;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    private MenuItem menuItem;

    private boolean mIsExit;
    private static MainActivity mainActivity;


    public  Tencent mTencent;
    private UserInfo mUserInfo;
    private BaseUiListener mIUiListener;
//    private String  figureurl,figureur2,figureur3;

    private ImageView imageView;
    private TextView textView,textView1;//textView 是昵称 textView1是用来获取值的
    private SearchView searchView;
    String url,nickName,userid ;
    private static final String TAG = "MainActivity";

    String Tag = "分享";
    String title = "生命周期";
    String APP_ID = "1110111320";



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        ActivityUtils.StatusBarLightMode(this);
        ActivityUtils.setStatusBarColor(this, R.color.white);//设置状态栏颜色
        initView();

        Toolbar toolbar = findViewById(R.id.toolbar);


        BottomNavigationView navView = findViewById(R.id.foot_nav_view);//抽屉的
        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        //searchView =(SearchView)findViewById(R.id.searchView);
        UserUtil userUtil = new UserUtil(MainActivity.this);

        setSupportActionBar(toolbar);
        setTitle(R.string.foot_menu_toutiao);
        setTitleCenter(toolbar);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();
        //这行是设置抽屉那些Item的，但是一直报错，先放过
        //navView.setOnNavigationItemSelectedListener(this);




        /*
        主要是imageloader的配置
         */

        Log.i(title,"11111111");
        mTencent = Tencent.createInstance(APP_ID, this.getApplicationContext());
        DisplayImageOptions op=new DisplayImageOptions.Builder().build();
        ImageLoaderConfiguration con=new ImageLoaderConfiguration.Builder(this)
                .defaultDisplayImageOptions(op)
                .build();
        ImageLoader.getInstance().init(con);
        setTitle(R.string.foot_menu_toutiao);
        setTitleCenter(toolbar);

//        fab.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
//                        .setAction("Action", null).show();
//                Log.i(title,"3333333");
//            }
//        });
        NavigationView navigationView = findViewById(R.id.nav_view);

        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
                UserUtil userUtil = new UserUtil(MainActivity.this);
                String Uid = userUtil.getUserId();
                Intent i;
                switch (menuItem.getItemId()) {
                    case R.id.nav_personal_center:  //个人中心
                        Toast.makeText(MainActivity.this, "点击了个人中心", Toast.LENGTH_SHORT).show();
                        break;
                    case R.id.nav_bookmark:     //收藏夹
                        Toast.makeText(MainActivity.this, "点击了收藏", Toast.LENGTH_SHORT).show();

                        if(Uid.equals("")){
                            Toast.makeText(MainActivity.this, "请先登录", Toast.LENGTH_SHORT).show();
                            break;
                        }
                        i=new Intent(MainActivity.this,CollectionActivity.class);
                        MainActivity.this.startActivity(i);
//                        startActivity(i);
                        break;
                    case R.id.nav_viewed:   //最近浏览
                        Toast.makeText(MainActivity.this, "点击了最近浏览", Toast.LENGTH_SHORT).show();

                        if(Uid.equals("")){
                            Toast.makeText(MainActivity.this, "请先登录", Toast.LENGTH_SHORT).show();
                            break;
                        }
                        i=new Intent(MainActivity.this,RecordActivity.class);
                        MainActivity.this.startActivity(i);
                        break;
                    case R.id.nav_version:   //版本信息
                        Toast.makeText(MainActivity.this, "点击了版本信息", Toast.LENGTH_SHORT).show();
                        i = new Intent(MainActivity.this,VersionInfoActivity.class);
                        MainActivity.this.startActivity(i);
                        break;
                    case R.id.nav_feedback:   //意见反馈
                        if(Uid.equals("")){
                            Toast.makeText(MainActivity.this, "请先登录", Toast.LENGTH_SHORT).show();
                            break;
                        }
                        Toast.makeText(MainActivity.this, "点击了意见反馈", Toast.LENGTH_SHORT).show();
                        i = new Intent(MainActivity.this,FankuiActivity.class);
                        i.putExtra("id",Uid);
                        MainActivity.this.startActivity(i);
                        break;
                    case R.id.nav_settings:   //设置
                        Toast.makeText(MainActivity.this, "点击了设置", Toast.LENGTH_SHORT).show();
                        break;
                }
                return true;
            }
        });

        View headerLayout=navigationView.getHeaderView(0);
        textView=headerLayout.findViewById(R.id.textView);
        //figure = headerLayout.findViewById(R.id.iv_figure);
        imageView=headerLayout.findViewById(R.id.imageView);
//        imageView = (ImageView)findViewById(R.id.imageView);
//        textView= (TextView) findViewById(R.id.textView);

        url = userUtil.getImageUrl();
        userid = userUtil.getUserId();
        nickName = userUtil.getUserName();
        Log.e("打开登录userid",""+userid);
        if(userid.equals("")){//UserId为空
            return;

        }else{
            url = userUtil.getImageUrl().toString();
            nickName = userUtil.getUserName();
            Log.e("打开登录url",""+url);
            Log.e("打开登录nickName",""+nickName);
            ImageLoader.getInstance().displayImage(url,imageView);
            textView.setText(""+nickName);
        }


        /*
        定位
         */

        List<String> permissionList = new ArrayList<>();
 if(ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){
 permissionList.add(Manifest.permission.ACCESS_FINE_LOCATION);
 }
 if(ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED){
 permissionList.add(Manifest.permission.READ_PHONE_STATE);
 }
if(ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
 permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
 }
 if(!permissionList.isEmpty()){
 String[] permissions =permissionList.toArray(new String[permissionList.size()]);
 ActivityCompat.requestPermissions(MainActivity.this, permissions, 1);
 }


    }


    @Override
    protected void onResume() {
        super.onResume();


        mTencent = Tencent.createInstance(APP_ID, this.getApplicationContext());
        //mTencent = Tencent.createInstance(APP_ID,this.getApplicationContext());
        Log.i(Tag,"3333333");
        String text = textView.getText().toString();
        Log.i(Tag, text);

            textView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(textView.getText().toString().equals("请登录")) {
                        Log.i(Tag, "---------------");
                        Login(v);
                    }
                    else  return;
                }
            });


            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(!textView.getText().toString().equals("请登录")){
                        new AlertDialog.Builder(MainActivity.this).setTitle("确认退出登录吗？")
                                .setIcon(android.R.drawable.ic_dialog_info)
                                .setPositiveButton("确定", new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        // 点击“确认”后的操作
                                        Log.i(Tag, "确认注销");
                                        Logout();

                                    }
                                })
                                .setNegativeButton("返回", new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        Log.i(Tag, "取消注销");
                                        // 点击“返回”后的操作,这里不设置没有任何操作
                                        return;
                                    }
                                }).show();

                    }else {
                        return;
                    }
            }
        });

//        button.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Log.i(Tag, "4444");
//                onClickShare();
//            }
//        });



//        button2.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Log.i(Tag, "注销");
//                Logout();
//
//            }
//        });
    }



    private void initView() {

        //默认 >3 的选中效果会影响ViewPager的滑动切换时的效果，故利用反射去掉
        //BottomNavigationViewHelper.disableShiftMode(navigation);

        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());

        adapter.addFragment(new TouTiaoFragment());
        adapter.addFragment(new HomeFragment());
        adapter.addFragment(new ZixunFragment());
        adapter.addFragment(new JingyingFragment());
        adapter.addFragment(new ShujuFragment());
        viewpager.setAdapter(adapter);
        viewpager.setCurrentItem(0);

        //缓存3个页面，来解决点击“我的”回来，首页空白的问题，
        // 存在的问题，如果有的页面不需要缓存该如何自动刷新，可以利用eventbus传参来进行该页面的操作
        viewpager.setOffscreenPageLimit(5);



        ///////// 一个不成熟的想法  viepager.setCurrenItem(0) 里得到是0就选择是0
        navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                        //Toolbar toolbar = findViewById(R.id.toolbar);
                switch (item.getItemId()) {
//                    case R.id.navigation_home:
                    case R.id.navigation_toutiao:
                        //toolbar.setTitle(R.string.foot_menu_toutiao);
                        viewpager.setCurrentItem(0);//头条
                        return true;
                    case R.id.navigation_zhidao:
                        //toolbar.setTitle(R.string.foot_menu_zhidao);
                        viewpager.setCurrentItem(1);//知道
                        return true;
                    case R.id.navigation_zixun:
                        //toolbar.setTitle(R.string.foot_menu_zixun);
                        viewpager.setCurrentItem(2);//咨询
                        return true;
                    case R.id.navigation_management:
                        //toolbar.setTitle(R.string.foot_menu_management);
                        viewpager.setCurrentItem(3);//经营
                        return true;
                    case R.id.navigation_shuju:
                        //toolbar.setTitle(R.string.foot_menu_shuju);
                        viewpager.setCurrentItem(4);//数据
                        return true;
                }
                return false;
            }
        });





        viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            Toolbar toolbar = findViewById(R.id.toolbar);
//            TextView textView = findViewById(R.id.txt1);
            //private String text = textView.getText().toString().trim();

            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                Log.e("切换","777777");
                System.out.println(viewpager.getCurrentItem());

                if (viewpager.getCurrentItem()==0){
                    toolbar.setTitle("头条");
                }if (viewpager.getCurrentItem()==1){
                    toolbar.setTitle("知道");
                }if (viewpager.getCurrentItem()==2){
                    toolbar.setTitle("咨询");
                }if (viewpager.getCurrentItem()==3){
                    toolbar.setTitle("经营");
                }if (viewpager.getCurrentItem()==4){
                    toolbar.setTitle("数据");
                }return;
            }

            @Override
            public void onPageSelected(int position) {
                Log.e("切换","111111111");
                if (menuItem != null) {
                    Log.e("切换","2222222");
                    menuItem.setChecked(false);
                } else {
                    Log.e("切换","3333333");
                    navigation.getMenu().getItem(0).setChecked(false);
                }
                Log.e("切换","444444");

                menuItem = navigation.getMenu().getItem(position);
                Log.e("切换","5555555");
                menuItem.setChecked(true);
            }

            @Override
            public void onPageScrollStateChanged(int state) {
                Log.e("切换","66666666");
//                toolbar.setTitle(R.string.foot_menu_change);
//                Log.e(Tag,""+textView.getText().toString());
                //Log.e(Tag,text);
//                toolbar.setTitle(textView.getText().toString());
            }
        });

     /*   //禁止ViewPager滑动
        viewPager.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });*/

    }


    /**
     * 双击退出应用
     *
     * @param keyCode
     * @param event
     * @return
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (mIsExit) {
                this.finish();
            } else {
                Toast.makeText(this, "再按一次退出", Toast.LENGTH_SHORT).show();
                mIsExit = true;
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mIsExit = false;
                    }
                }, 2000);
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {

        }
    }

    /*
     * 点击知道的搜索后
     */
    public void ClickSearch(View view){
        Intent intent = new Intent(MainActivity.getMainActivity(),SearchviewActivity.class);
        startActivity(intent);
    }
    /*
     * 设置标题居中
     */
    public void setTitleCenter(Toolbar toolbar) {
        String title = "title";
        final CharSequence originalTitle = toolbar.getTitle();
        toolbar.setTitle(title);
        for (int i = 0; i < toolbar.getChildCount(); i++) {
            View view = toolbar.getChildAt(i);
            if (view instanceof TextView) {
                TextView textView = (TextView) view;
                if (title.equals(textView.getText())) {
                    textView.setGravity(Gravity.CENTER);
                    Toolbar.LayoutParams params = new Toolbar.LayoutParams(Toolbar.LayoutParams.WRAP_CONTENT, Toolbar.LayoutParams.MATCH_PARENT);
                    params.gravity = Gravity.CENTER;
                    textView.setLayoutParams(params);
                }
            }
            toolbar.setTitle(originalTitle);
        }
    }


    /*
     * 分享到QQ
     */
    private void onClickShare() {
        final Bundle params = new Bundle();
        Log.i(Tag, "5555");
        params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
        Log.i(Tag, "6666");
        params.putString(QQShare.SHARE_TO_QQ_TITLE, "测试成功");
        Log.i(Tag, "77777");
        params.putString(QQShare.SHARE_TO_QQ_SUMMARY,  "这是一个测试");
        Log.i(Tag, "88888");
        params.putString(QQShare.SHARE_TO_QQ_TARGET_URL,  "http://jwc.jmu.edu.cn/");
        Log.i(Tag, "9999");
        params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL,"http://jwc.jmu.edu.cn/images/201502.jpg");
        Log.i(Tag, "10");
        params.putString(QQShare.SHARE_TO_QQ_APP_NAME,  "酒知道");
        Log.i(Tag, "11");
        //mTencent.shareToQQ(MainActivity.this, params, new ShareUiListener());
        Log.i(Tag, "12");
    }
    /*
     * 分享到QQ的异常监听器
     */
    private class ShareUiListener implements IUiListener {

        @Override
        public void onComplete(Object response) {
            Log.i(Tag,"13");
            //分享成功
        }

        @Override
        public void onError(UiError uiError) {
            Log.i(Tag,"失败");
            //分享失败
        }

        @Override
        public void onCancel() {
            Log.i(Tag,"取消分享");
            //分享取消
        }
    }


    /*
     * QQ注销
     */
    public void Logout( ){
        Log.e(Tag,"注销");
        mTencent.logout(this);
        textView.setText("请登录");
        imageView.setImageResource(R.mipmap.icon_menu_unlogin);
        UserUtil userUtil = new UserUtil(MainActivity.this);
        userUtil.setOpenId("");//退出清空
        userUtil.setUserId("");
        userUtil.setImageUrl("");
        userUtil.setUserName("");

        //imageView.setImageResource(R.mipmap.ic_launcher);
        Log.e(Tag,"注销成功");
        Toast.makeText(this, "未登录！请登录", Toast.LENGTH_SHORT).show();

    }

    /*
     * QQ登录
     */
    public void Login(View v) {
        /**通过这句代码，SDK实现了QQ的登录，这个方法有三个参数，第一个参数是context上下文，第二个参数SCOPO 是一个String类型的字符串，表示一些权限
         官方文档中的说明：应用需要获得哪些API的权限，由“，”分隔。例如：SCOPE = “get_user_info,add_t”；所有权限用“all”
         第三个参数，是一个事件监听器，IUiListener接口的实例，这里用的是该接口的实现类 */
        mIUiListener = new BaseUiListener();
        //all表示获取所有权限
        mTencent.login(MainActivity.this, "all", mIUiListener);


    }



    /**
     * 自定义监听器实现IUiListener接口后，需要实现的3个方法
     * onComplete完成 onError错误 onCancel取消
     */
    private class BaseUiListener implements IUiListener {
        private String path = "http://212.64.93.57:8080/User/login?";
        @Override
        public void onComplete(Object response) {
            Toast.makeText(MainActivity.this, "授权成功", Toast.LENGTH_SHORT).show();
            Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
            Toast.makeText(MainActivity.this, "登录后点击头像退出哦", Toast.LENGTH_LONG).show();
            Log.e(TAG, "response:" + response);
            JSONObject obj = (JSONObject) response;
            try {
                String openID = obj.getString("openid");
                Log.e("登录", "openid:" + openID);
                String accessToken = obj.getString("access_token");
                Log.e("登录", "accessToken:" + accessToken);
                String expires = obj.getString("expires_in");
                Log.e("登录", "expires:" + expires);

//               name = obj.getString("nickname");
////                //figureurl = obj.getString("figureurl_qq_2");  //头像图片的url
////                /*Log.i("imgUrl",figureurl.toString()+"");*/
//               textView.setText(name);
//               Log.e("登录","nickname"+name);
//                /*Glide.with(MainActivity.this).load(figureurl).into(figure);*/
//                //Uri parse = Uri.parse(figureurl);
//                //figure.setImageURI(parse);

                mTencent.setOpenId(openID);
                mTencent.setAccessToken(accessToken, expires);
                QQToken qqToken = mTencent.getQQToken();
                mUserInfo = new UserInfo(getApplicationContext(), qqToken);
                mUserInfo.getUserInfo(new IUiListener() {
                    @Override
                    public void onComplete(Object response) {
                        Log.e(TAG, "登录成功" + response.toString());


                        try {
                            JSONObject re = (JSONObject) response;
                            int ret = re.getInt("ret");
                            System.out.println("json=" + String.valueOf(re));
                            String nickName = re.getString("nickname");
                            //String gender = re.getString("gender");
//                            figureurl = re.getString("figureurl_qq_2");  //头像图片的url 100*100
//                            figureur2 = re.getString("figureurl_1");//50*50
//                            figureur3 = re.getString("figureurl_qq");//140*140
                            String url=re.getString("figureurl_qq");



//                            Log.e("登录","figureurl:"+figureurl);
//                            Log.e("登录","figureur2:"+figureur2);
//                            Log.e("登录","figureur3:"+figureur3);
                            //parse = Uri.parse(figureurl);

                            //Log.e("登录","parse:"+parse);
                            //figure.setImageURI(parse);
                            Log.e("登录","nickname1:"+nickName);
                            Log.e("登录","url:"+url);
                            textView.setText(""+nickName);
                            Log.e("登录","设置名");
                            //imageView.setImageURI(parse);
                            //figure.setImageURI(parse);
                            ImageLoader.getInstance().displayImage(url,imageView);
                            Log.e("登录","设置头像");

                            //openId=12345617&name=1&imgUrl=sdasdasd
                            //OkHttpUtil.getRequest(path+"openId="+openID+"&name="+nickName+"&name="+url);
                            Log.e("登录path",path+"openId="+openID+"&name="+nickName+"&imgUrl="+url);
                           String httpurl = OkHttpUtil.getRequest(path+"openId="+openID+"&name="+nickName+"&imgUrl="+url);


                            com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(httpurl);
                            Log.e("登录",httpurl);
                            userid = jsonObject.getString("data");
                            Log.e("登录userid",userid);


                            //登录成功后存储信息进my_sp文件中 sharepreferences
                            UserUtil userUtil = new UserUtil(MainActivity.this);
                            userUtil.setOpenId(openID);
                            userUtil.setUserId(userid);
                            userUtil.setImageUrl(url);
                            userUtil.setUserName(nickName);

//                            userUtil.getUserId();
//                            userUtil.getUserName(); 取值
//                            userUtil.getImageUrl();
//                            userUtil.getOpenId();



                        } catch (JSONException e) {
                            e.printStackTrace();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }


                    }

                    @Override
                    public void onError(UiError uiError) {
                        Log.e(TAG, "登录失败" + uiError.toString());
                    }

                    @Override
                    public void onCancel() {
                        Log.e(TAG, "登录取消");

                    }
                });
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(UiError uiError) {
            Toast.makeText(MainActivity.this, "授权失败，未成功登录", Toast.LENGTH_SHORT).show();

        }

        @Override
        public void onCancel() {
            Toast.makeText(MainActivity.this, "授权取消，未成功登录", Toast.LENGTH_SHORT).show();

        }

    }

    /**
     * 在调用Login的Activity或者Fragment中重写onActivityResult方法
     *
     * @param requestCode
     * @param resultCode
     * @param data
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == Constants.REQUEST_LOGIN) {
            Tencent.onActivityResultData(requestCode, resultCode, data, mIUiListener);
        }
        super.onActivityResult(requestCode, resultCode, data);
    }


    public MainActivity() {
        mainActivity = this;
    }

    public static MainActivity getMainActivity() {
        return mainActivity;
    }





}
